package com.penghaisoft.microwms.base.web.data.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.ws.rs.core.MediaType;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.penghaisoft.microwms.base.web.data.service.IMdModelService;
import com.penghaisoft.microwms.base.web.data.service.IMdProModelService;
import com.penghaisoft.microwms.common.Constant;
import com.penghaisoft.microwms.common.controller.BaseController;
import com.penghaisoft.microwms.common.data.model.MdModel;
import com.penghaisoft.microwms.common.data.model.MdModelMes;
import com.penghaisoft.microwms.common.data.model.MdProModel;
import com.penghaisoft.microwms.common.dto.HandResp;
import com.penghaisoft.microwms.common.dto.Resp;
import com.penghaisoft.microwms.common.dto.TransResult;
import com.penghaisoft.microwms.common.page.Pager;
import com.penghaisoft.microwms.common.service.IMesInterfaceService;
import com.penghaisoft.microwms.common.service.MesProperties;


@RestController
@RequestMapping(value = "/data/promodel")
@Slf4j
public class MdProModelController extends BaseController {
	
	@Autowired
	private IMdProModelService mdProModelService;

	 /**
	   * 新增记录
	   * @param mdProModel
	   * @return
	   */
		@PostMapping("c")
		public TransResult create(MdProModel mdProModel) {
			mdProModel.preInsert();
			mdProModel.setActiveFlag("1");
			Resp resp =  mdProModelService.create(mdProModel);
			return fromResp(resp);
		}

	  /**
	   * 删除记录（逻辑删除active_flag=0)
	   * @param mdProModel
	   * @return
	   */
		@PostMapping("d")
		public TransResult delete(MdProModel mdProModel) {
			mdProModel.preUpdate();
			Resp resp =  mdProModelService.delete(mdProModel);
			return fromResp(resp);
		}

	  /**
	   * 查询列表
	   * @param pager
	   * @return
	   */
		@PostMapping("list")
		public TransResult list(@RequestParam(name = "page", defaultValue = "1") int page,
                          @RequestParam(name = "rows", defaultValue = "10") int rows,MdProModel mdProModel) {
			Pager<MdProModel> result = mdProModelService.findListByCondition(page,rows,mdProModel);
			return success(result);
		}

	  /**
	   * 查询单条
	   * @param id
	   * @return
	   */
		@GetMapping("r/{id}")
		public TransResult queryById(@PathVariable String id) {
			MdProModel  mdProModel = mdProModelService.findById(id);
			return success(mdProModel);
		}

	  /**
	   * 修改记录
	   * @param mdProModel
	   * @return
	   */
		@PostMapping("u")
		public TransResult update(MdProModel mdProModel) {
			mdProModel.preUpdate();
			Resp resp =  mdProModelService.update(mdProModel);
	    	return fromResp(resp);
		}

}
